package com.administrator.cloudapplication.activitys;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.base.BaseActivity;
import com.administrator.cloudapplication.constant.Urls;
import com.administrator.cloudapplication.models.NearLibraryModel;
import com.bumptech.glide.Glide;

/**
 * Created by Administrator on 2017/4/21.
 */

public class NearDetailActivity extends BaseActivity {
    private WebView mWebView;
    NearLibraryModel.DataBean mDataBean;
    String url, img_url,xcor,ycor;
    ImageView mImageView, img_phone;
    TextView tv_name, tv_address;
    Intent intent;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_neardetail);
        mWebView = (WebView) findViewById(R.id.wv_neardetail);
        mImageView = (ImageView) findViewById(R.id.img_neardetail);
        img_phone = (ImageView) findViewById(R.id.ib_phone);
        tv_name = (TextView) findViewById(R.id.tv_lirbrary_name);
        tv_address = (TextView) findViewById(R.id.tv_address);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setSupportZoom(true);
        webSettings.setDisplayZoomControls(true);
        webSettings.setJavaScriptEnabled(true);
    }

    @Override
    protected void initData() {
        mDataBean = (NearLibraryModel.DataBean) getIntent().getSerializableExtra("mDataBean");
        xcor=mDataBean.getXCoordinate();
        ycor=mDataBean.getYCoordinate();
        img_url = Urls.IMG_URL + mDataBean.getThumb();
        Glide.with(mContext).load(img_url).placeholder(R.mipmap.error).error(R.mipmap.error).into(mImageView);
        tv_name.setText(mDataBean.getName());
        tv_address.setText(mDataBean.getAddress());
        url = Urls.BASE_URL + Urls.LIBRARY_DETAIL + "/" + mDataBean.getId();
        mWebView.loadUrl(url);
        tv_address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if("0".equals(xcor)|"0".equals(ycor)){
                    Toast.makeText(NearDetailActivity.this,"获取地理位置失败",Toast.LENGTH_SHORT).show();
                }
                else {
                    intent = new Intent(NearDetailActivity.this, MapActivity.class);
                    intent.putExtra("xcor",xcor);
                    intent.putExtra("ycor",ycor);
                    startActivity(intent);
                }

            }
        });
        img_phone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String phone_number = mDataBean.getTel();
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone_number));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                NearDetailActivity.this.startActivity(intent);
            }
        });
    }

    @Override
    protected void onLeftClick() {

    }

    @Override
    protected void onRightClick() {

    }
}
